{% extends "base.html" %}

{% block title %}Control Structures - Flask Templates Demo{% endblock %}

{% block content %}
<h2>Template Control Structures</h2>

<div class="row">
    <div class="col-md-6">
        <h3>Conditional Statements</h3>
        <p>Current user: <strong>{{ user.username }}</strong></p>
        
        {% if user.username == "admin" %}
            <div class="alert alert-success">
                <p>Welcome, administrator! You have special privileges.</p>
            </div>
        {% elif user.username == "guest" %}
            <div class="alert alert-info">
                <p>Welcome, guest! Please log in for full access.</p>
            </div>
        {% else %}
            <div class="alert alert-warning">
                <p>Welcome, {{ user.username }}! Enjoy your visit.</p>
            </div>
        {% endif %}
        
        <h3>Loops with Conditions</h3>
        {% if movies %}
            <p>High-rated movies (8+):</p>
            <ul>
            {% for movie in movies if movie.rating >= 8 %}
                <li>{{ movie.name }} ({{ movie.year }}) - Rating: {{ movie.rating }}/10</li>
            {% else %}
                <li>No high-rated movies found.</li>
            {% endfor %}
            </ul>
        {% endif %}
    </div>
    
    <div class="col-md-6">
        <h3>Loop Controls</h3>
        {% if movies %}
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Movie</th>
                        <th>Year</th>
                    </tr>
                </thead>
                <tbody>
                    {% for movie in movies %}
                        {% if loop.index <= 5 %}  {# Only show first 5 #}
                            <tr class="{% if loop.first %}table-primary{% elif loop.last %}table-secondary{% endif %}">
                                <td>{{ loop.index }}</td>
                                <td>{{ movie.name }}</td>
                                <td>{{ movie.year }}</td>
                            </tr>
                        {% elif loop.index == 6 %}
                            <tr>
                                <td colspan="3" class="text-center">... and {{ movies|length - 5 }} more movies</td>
                            </tr>
                        {% endif %}
                    {% endfor %}
                </tbody>
            </table>
        {% endif %}
    </div>
</div>

<div class="mt-4">
    <h3>Dictionary Iteration</h3>
    <p>User information:</p>
    <ul>
    {% for key, value in user.items() %}
        <li><strong>{{ key|title }}:</strong> {{ value }}</li>
    {% endfor %}
    </ul>
</div>
{% endblock %}